//
//  UIView+Extension.swift
//  webo
//
//  Created by apple on 2016/11/19.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

extension UIImage{
    
    class  func getCurrentImage() -> UIImage {
        
        let window = UIApplication.shared.keyWindow!
        
        UIGraphicsBeginImageContextWithOptions(window.frame.size, false, 0)
        
        window.drawHierarchy(in: window.frame, afterScreenUpdates: true)
        
        let image = UIGraphicsGetImageFromCurrentImageContext()
        
        UIGraphicsEndImageContext()
        
        return image!
    }

      func dealScaleImg(width: CGFloat) -> UIImage{
        let imgw = self.size.width
        let imgh = self.size.height
        if imgw < width {
            return self
        }
        let height = imgh / imgw * width
        UIGraphicsBeginImageContextWithOptions(CGSize(width:width , height: height), false, 0 )
        self.draw(in: CGRect(x: 0, y: 0, width: width, height: height))
        let img = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return img!
    }

}
